<?php

require PATH_MODELS . 'MenuModel.class.php';

/**
 * 网站管理
 */
class WebPage extends BasePage {

    private $M;
    private $way = '';
    // 产品菜单表
    static private $db_proudct_menu = 'tb_product_menu';
    // 产品详情表
    static private $proudct_list = 'tb_proudct_list';
    // 用户表
    static private $user_menu = 'tb_usre';
    // 产品信息分类表
    static private $product_categroy = 'tb_product_category';
    // 产品信息分类列表
    static private $product_categroy_list = 'tb_product_category_list';

    /**
     * 构造方法
     */
    function __construct() {
        parent::checkUserLogin();
        $this->M = new MenuModel();
        $this->way = isset($_GET['way']) ? trim($_GET['way']) : '';
        parent::getMenuList($this->M);
    }

    /**
     * ajax 取产品菜单二级联动数据
     */
    function menuGrade() {
        $pid = $_GET['pid'];
        $tnp = $this->M->getLIst(self::$db_proudct_menu, 'Fid,FcateId,Fname', 'WHERE  FcateId=' . $pid, 'ORDER BY Fsort');
        $select_data[$pid] = $tnp;
        if ($pid == 0) {
            exit;
        }
        echo '<option value="0">' . "请选择下级" . '</option>';
        foreach ($select_data[$pid] as $ls) {
            echo '<option value="' . $ls['Fid'] . '">' . $ls['Fname'] . '</option>';
        }
    }

    /**
     * ajax 取产品菜单二级联动数据
     */
    function menuSub() {
        $pid = $_GET['pid'];
        $tnp = $this->M->getLIst(self::$db_proudct_menu, 'Fid,FcateId,Fname', 'WHERE  FcateId=' . $pid, 'ORDER BY Fsort');
        $select_data[$pid] = $tnp;
        if ($pid == 0) {
            exit;
        }
        echo '<option value="0">' . "请选择下级" . '</option>';
        foreach ($select_data[$pid] as $ls) {
            echo '<option value="' . $ls['Fid'] . '">' . $ls['Fname'] . '</option>';
        }
    }

    /**
     * 资讯分类管理
     */
    function info() {
        if ($this->way == "A") {
            if (!$_POST) {
                include PATH_VIEWS . 'web/info/add.php';
            }
        }

        if ($this->way == "S") {
            if (!$_POST) {
                include PATH_VIEWS . 'web/info/list.php';
            }
        }
    }

    /**
     * 网站信息管理
     */
    function webInfo() {
        if ($this->way == "S") {
            include PATH_VIEWS . 'web/webinfo/list.php';
        }
    }

    /**
     * 商品菜单管理
     */
    function productMenu() {
        // 商品分类添加
        if ($this->way == "A") {
            if (!$_POST) {
                // 取等级顶级菜单
                $menu_list = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', 'WHERE Flevel=1');
                include PATH_VIEWS . 'web/product_menu/add.php';
            } else {
                $user_id = BaseYspCookie::getCookie($_COOKIE['admin']['id']);
                $edit = $this->M->getOneRow(self::$user_menu, 'Fname', "WHERE Fid=$user_id");
                $cate_id_arr = $_POST['FcateIds'];
                array_unshift($cate_id_arr, '0');
                $cate_id_arr = array_unique($cate_id_arr);
                $cate_ids = implode(',', $cate_id_arr);
                $data = array(
                    'FcateIds' => $cate_ids,
                    'FcateId' => isset($cate_id_arr) ? end($cate_id_arr) : 0,
                    'Fname' => isset($_POST['Fname']) ? trim($_POST['Fname']) : '',
                    'Fsort' => isset($_POST['Fsort']) ? intval($_POST['Fsort']) : 0,
                    'Flevel' => count($cate_id_arr),
                    'Fstatus' => isset($_POST['Fstatus']) ? intval($_POST['Fstatus']) : 1,
                    'FaddPersonId' => $user_id,
                    'FaddpersonName' => $edit['Fname'],
                    'FtotalProductNum' => isset($_POST['FtotalProductNum']) ? intval($_POST['FtotalProductNum']) : 0
                );
                $rs = $this->M->addMenu(self::$db_proudct_menu, $data);
                if ($rs > 0) {
                    parent::getMsg('right', '操作成功', URL);
                } else {
                    parent::getMsg('wrong', '操作失败', URL);
                }
            }
        }

        // 商品分类列表
        if ($this->way == "S") {
            //分页参数设置
            //当前页码
            $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            //每页条数
            $pagesize = 10;
            $page = ($page < 1) ? 1 : $page;
            //起始条数
            $start = ($page - 1) * $pagesize;
            //查询关键字
            $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
            $words_arr = BaseYsp::wordsFilter($keywords);
            $where = "WHERE Fid>=1";
            if (!empty($keywords)) {
                foreach ($words_arr as $wd) {
                    $where .= " AND (Fname LIKE '%$wd%')";
                }
            }
            $where = $keywords ? "WHERE Fname LIKE '%$keywords%'" : '';

            //取总记录数
            $total = $this->M->getTotal(self::$db_proudct_menu, $where);
            $info_list = $this->M->getList(self::$db_proudct_menu, '*', $where, 'ORDER BY FcateId,Flevel,Fsort', "LIMIT $start,$pagesize");
            if ($total > 0) {
                $cate_ids = 0;
                foreach ($info_list as $ls) {
                    $cate_ids .= ',' . $ls['FcateIds'];
                }
                //取所有菜单，构造数组
                $categroy = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', "WHERE Fid IN ($cate_ids)");
                $category_arr[0] = '顶级';
                foreach ($categroy as $ls) {
                    $category_arr[$ls['Fid']] = $ls['Fname'];
                }
                $Pager = new ExtendsYspPager();
                $pagerlink = $Pager->getPager($total, $page, $pagesize);
            } else {
                $pagerlink = '对不起，没有相关信息';
            }
            include PATH_VIEWS . 'web/product_menu/list.php';
        }
        // 商品菜单编辑
        if ($this->way == "E") {
            if (!$_POST) {
                // 取等级顶级菜单
                $menu_list = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', 'WHERE Flevel=1');
                // 取当前的修改的一条信息
                $edit = $this->M->getView(self::$db_proudct_menu, 'Fid');
                $cate_ids = $edit['FcateIds'];
                // 锁定一级菜单
                $cate_id_arr = explode(',', $cate_ids);
                $cate_id = isset($cate_id_arr[1]) ? intval($cate_id_arr[1]) : 0;
                // 取二级菜单
                $two_id = end($cate_id_arr);
                if ($edit['Flevel'] == 3) {
                    $cate_two_menu = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', "WHERE Flevel = 2 AND FcateId =$cate_id ");
                }
                include PATH_VIEWS . 'web/product_menu/edit.php';
            } else {
                
            }
        }
        // 商品菜单删除
        if ($this->way == "D") {
            $rs = $this->M->Del(self::$db_proudct_menu, 'Fid');
            if ($rs !== false) {
                $href = str_replace('&way=D', '&way=S', URL);
                parent::getMsg('right', '操作成功', $href);
                exit;
            } else {
                parent::getMsg('wrong', '对不起，操作失败', URL);
                exit;
            }
        }
    }

    // 文件上传测试
    function upload() {
        if ($this->way == "A") {
            if (!$_POST) {
                include PATH_VIEWS . 'web/upload_test/add.php';
            } else {
                $data = array(
                    "Ftitle" => isset($_POST['name']) ? trim($_POST['name']) : '',
                    "Fsort" => isset($_POST['sort']) ? trim($_POST['sort']) : ''
                );
                //                判断上传的图片是否存在并且不能为空
                if (isset($_FILES['img']['name']) && !empty($_FILES['img']['name'])) {
//                基本使用方法:
                    $file = new ExtendsYspUploadFile();
                    $file->max_size = 2 * 1024 * 1024; //       //限制文件大小 字节
                    $file->allow_type = "gif/jpg/bmp/png"; //允许上传的文件类型
                    $file->input_name = "img";           //表单中的文本域名称
                    $file->save_path = PATH_UPLOAD . 'test';      //保存路径
                    $file->rand_name = false;                   //随机文件名 (默认)
                    $file->reset_name = time() . '_' . BaseYspCookie::getCookie($_COOKIE['admin']['id']) . '_' . rand(0, 100);   //重命名
                    if ($file->save()) {
//                    echo "ok";               //保存文件，成功返回 true
                        $data['Fimg'] = str_replace(PATH_UPLOAD, '', $file->file_upload_path);
                    }
                }
                $rs = $this->M->addMenu('tb_test_upload', $data);
                if ($rs > 0) {
                    $href = str_replace('way=A', 'way=S', URL);
                    parent::getMsg('right', '操作成功', $href, $time = 3);
                } else {
                    parent::getMsg('wrong', '操作失败', URL);
                }
            }
        }
        if ($this->way == "S") {
            $info_list = $this->M->getList('tb_test_upload', '*');
            include PATH_VIEWS . 'web/upload_test/list.php';
        }

        if ($this->way == "E") {
            if (!$_POST) {
                $pid = isset($_GET['primarykey']) ? intval($_GET['primarykey']) : 0;
                $edit = $this->M->getView('tb_test_upload', 'Fid');
                include PATH_VIEWS . 'web/upload_test/edit.php';
            } else {
                
            }
        }

        if ($this->way == "D") {
            $rs = $this->M->Del('tb_test_upload', 'Fid');
            if ($rs !== false) {
                $href = str_replace('&way=D', '&way=S', URL);
                parent::getMsg('right', '操作成功', $href);
                exit;
            } else {
                parent::getMsg('wrong', '对不起，操作失败', URL);
                exit;
            }
        }
    }

    /**
     * 多图处理
     */
    function manyImg() {
        $pid = isset($_GET['primarykey']) ? intval($_GET['primarykey']) : 0;
        $times = $this->M->getProductImgNum('tb_test_upload', $pid);
        //                判断上传的图片是否存在并且不能为空
        if (isset($_FILES['Filedata']['name']) && !empty($_FILES['Filedata']['name'])) {
//                基本使用方法:
            $file = new ExtendsYspUploadFile();
            $file->max_size = 2 * 1024 * 1024; //       //限制文件大小 字节
            $file->allow_type = "gif/jpg/bmp/png"; //允许上传的文件类型
            $file->input_name = "Filedata";           //表单中的文本域名称
            $file->save_path = PATH_UPLOAD . 'test';      //保存路径
            $file->rand_name = false;                   //随机文件名 (默认)
            $times++;
            $file->reset_name = time() . '_' . BaseYspCookie::getCookie($_COOKIE['admin']['id']) . '_' . $times;   //重命名
            if ($file->save()) {
//                    echo "ok";               //保存文件，成功返回 true
                $current_image_path = $data['Fimg'] = str_replace(PATH_UPLOAD, '', $file->file_upload_path);
                $this->M->updateMoreImage('tb_test_upload', $pid, $current_image_path);
                echo 1;
                exit;
            } else {
                echo 0;
                exit;
            }
        }
    }

    /**
     * 商品管理 
     */
    function proudct() {
        // 取商品信息分类菜单
        $info_list = $this->M->getList(self::$product_categroy_list);
        $info_list_array = array();
        foreach ($info_list as $value) {
            $info_list_array[$value['FcateId']][$value['Fid']] = $value;
        }
        // add
        if ($this->way == "A") {
            if (!$_POST) {
                // 取商品顶级菜单
                $menu_list = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', 'WHERE Flevel=1');

                include PATH_VIEWS . 'web/product/add.php';
            } else {
                $user_id = BaseYspCookie::getCookie($_COOKIE['admin']['id']);
                $edit = $this->M->getOneRow(self::$user_menu, 'Fname', "WHERE Fid=$user_id");
                $cate_id_arr = $_POST['FcateIds'];
                if (count($cate_id_arr) < 3 || empty($cate_id_arr)) {
                    parent::getMsg('wrong', '请选择商品二级菜单', URL);
                }
                if (end($cate_id_arr) == 0) {
                    parent::getMsg('wrong', '请选择商品三级级菜单', URL);
                }
                // 上级菜单处理
                array_unshift($cate_id_arr, '0');
                $cate_id_arr = array_unique($cate_id_arr);
                $cate_ids = implode(',', $cate_id_arr);
                // 商品信息分类处理
                $info_id = $_POST['FinfoIds'];
                $info_id_arrs = array_diff($info_id, array(0));
                $info_id_arr = implode(',', $info_id_arrs);

                $data = array(
                    'FcateIds' => $cate_ids,
                    'FinfoIds' => $info_id_arr,
                    'FcateId' => isset($cate_id_arr) ? end($cate_id_arr) : 0,
                    'Ftitle' => isset($_POST['Ftitle']) ? trim($_POST['Ftitle']) : '',
                    'Fstitle' => isset($_POST['Fstitle']) ? trim($_POST['Fstitle']) : '',
                    'FenTitle' => isset($_POST['FenTitle']) ? trim($_POST['FenTitle']) : '',
                    'Fprice' => isset($_POST['Fprice']) ? floatval($_POST['Fprice']) : 0,
                    'Fdiscount' => isset($_POST['Fdiscount']) ? floatval($_POST['Fdiscount']) : 0,
                    'Fpostage' => isset($_POST['Fpostage']) ? floatval($_POST['Fpostage']) : 0,
                    'FproudctNum' => isset($_POST['FproudctNum']) ? intval($_POST['FproudctNum']) : 0,
                    'Fsort' => isset($_POST['Fsort']) ? intval($_POST['Fsort']) : 1,
                    'Fstatus' => isset($_POST['Fstatus']) ? intval($_POST['Fstatus']) : 1,
                    'FlimitBuy' => isset($_POST['FlimitBuy']) ? intval($_POST['FlimitBuy']) : 0,
                    'Fdetails' => isset($_POST['Fdetails']) ? trim($_POST['Fdetails']) : '',
                    'FaddTime' => time(),
                    'FaddPersonId' => $user_id,
                    'FaddpersonName' => $edit['Fname']
                );
//                判断上传的图片是否存在并且不能为空
                if (isset($_FILES['Fimg']['name']) && !empty($_FILES['Fimg']['name'])) {
//                基本使用方法:
                    $file = new ExtendsYspUploadFile();
                    $file->max_size = 2 * 1024 * 1024; //       //限制文件大小 字节
                    $file->allow_type = "gif/jpg/bmp/png"; //允许上传的文件类型
                    $file->input_name = "Fimg";           //表单中的文本域名称
                    $file->save_path = PATH_UPLOAD . 'proudct';      //保存路径
                    $file->rand_name = false;                   //随机文件名 (默认)
                    $file->reset_name = time() . '_' . BaseYspCookie::getCookie($_COOKIE['admin']['id']) . '_' . rand(0, 100);   //重命名
                    if ($file->save()) {
//                    echo "ok";               //保存文件，成功返回 true
                        $data['Fimg'] = str_replace(PATH_UPLOAD, '', $file->file_upload_path);
                    }
                }

                $rs = $this->M->addMenu(self::$proudct_list, $data);
                if ($rs > 0) {
                    parent::getMsg('right', '操作成功,您可以添加更多产品附图', URL);
                } else {
                    parent::getMsg('wrong', '操作失败', URL);
                }
            }
        }
        // list
        if ($this->way == "S") {
            //分页参数设置
            //当前页码
            $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            //每页条数
            $pagesize = 10;
            $page = ($page < 1) ? 1 : $page;
            //起始条数
            $start = ($page - 1) * $pagesize;
            //查询关键字
            $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
            $words_arr = BaseYsp::wordsFilter($keywords);
            $where = "WHERE Fid>=1";
            if (!empty($keywords)) {
                foreach ($words_arr as $wd) {
                    $where .= " AND (Fname LIKE '%$wd%')";
                }
            }
            $where = $keywords ? "WHERE Fname LIKE '%$keywords%'" : '';

            //取总记录数
            $total = $this->M->getTotal(self::$proudct_list, $where);
            $info_list = $this->M->getList(self::$proudct_list, '*', $where, 'ORDER BY FcateId,Fsort', "LIMIT $start,$pagesize");
            if ($total > 0) {
                $cate_ids = 0;
                foreach ($info_list as $ls) {
                    $cate_ids .= ',' . $ls['FcateIds'];
                }
                //取所有菜单，构造数组
                $categroy = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', "WHERE Fid IN ($cate_ids)");
                $category_arr[0] = '顶级';
                foreach ($categroy as $ls) {
                    $category_arr[$ls['Fid']] = $ls['Fname'];
                }
                $Pager = new ExtendsYspPager();
                $pagerlink = $Pager->getPager($total, $page, $pagesize);
            } else {
                $pagerlink = '对不起，没有相关信息';
            }
            include PATH_VIEWS . 'web/product/list.php';
        }
        // edit
        if ($this->way == "E") {
            if (!$_POST) {
                $pid = isset($_GET['primarykey']) ? intval($_GET['primarykey']) : 0;
                // 取等级顶级菜单
                $menu_list = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', 'WHERE Flevel=1');
                // 取当前修改信息
                $edit = $this->M->getView(self::$proudct_list, 'Fid');
                $level = count(explode(',', $edit['FcateIds']));
                $cate_ids = $edit['FcateIds'];
                // 锁定一级菜单
                $cate_id_arr = explode(',', $cate_ids);
                $cate_id = isset($cate_id_arr[1]) ? intval($cate_id_arr[1]) : 0;
                // 取二级菜单
                $two_id = array_slice($cate_id_arr, -2, 1);
                $two_id = $two_id[0];
                if ($level > 3) {
                    $cate_two_menu = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', "WHERE Flevel = 2 AND FcateId =$cate_id ");
                }
                // 取三级菜单
                $three_id = end($cate_id_arr);
                if ($level >= 4) {
                    $cate_three_menu = $this->M->getList(self::$db_proudct_menu, 'Fid,Fname', "WHERE Flevel = 3 AND FcateId =$two_id ");
                }
                $info_id_arrs = explode(',', $edit['FinfoIds']);
                // 构造信息菜单自己的ID对应自己的名字
                $info_list_menu = array();
                foreach ($info_list as $val) {
                    $info_list_menu[$val['Fid']] = $val['Fname'];
                }
                include PATH_VIEWS . 'web/product/edit.php';
            } else {
                $user_id = $_SESSION['admin']['id'];
                $edit = $this->M->getOneRow(self::$user_menu, 'Fname', "WHERE Fid=$user_id");
                $cate_id_arr = $_POST['FcateIds'];
                if (count($cate_id_arr) < 3 || empty($cate_id_arr)) {
                    parent::getMsg('wrong', '请选择商品二级菜单', URL);
                }
                if (end($cate_id_arr) == 0) {
                    parent::getMsg('wrong', '请选择商品三级级菜单', URL);
                }
                // 菜单构造
                array_unshift($cate_id_arr, '0');
                $cate_id_arr = array_unique($cate_id_arr);
                $cate_ids = implode(',', $cate_id_arr);
                // 商品信息分类处理
                $info_id = $_POST['FinfoIds'];
                $info_id_arrs = array_diff($info_id, array(0));
                $info_id_arr = implode(',', $info_id_arrs);
                $data = array(
                    'FcateIds' => $cate_ids,
                    'FinfoIds' => $info_id_arr,
                    'FcateId' => isset($cate_id_arr) ? end($cate_id_arr) : 0,
                    'Ftitle' => isset($_POST['Ftitle']) ? trim($_POST['Ftitle']) : '',
                    'Fstitle' => isset($_POST['Fstitle']) ? trim($_POST['Fstitle']) : '',
                    'FenTitle' => isset($_POST['FenTitle']) ? trim($_POST['FenTitle']) : '',
                    'Fprice' => isset($_POST['Fprice']) ? floatval($_POST['Fprice']) : 0,
                    'Fdiscount' => isset($_POST['Fdiscount']) ? floatval($_POST['Fdiscount']) : 0,
                    'Fpostage' => isset($_POST['Fpostage']) ? floatval($_POST['Fpostage']) : 0,
                    'FproudctNum' => isset($_POST['FproudctNum']) ? intval($_POST['FproudctNum']) : 0,
                    'Fsort' => isset($_POST['Fsort']) ? intval($_POST['Fsort']) : 1,
                    'Fstatus' => isset($_POST['Fstatus']) ? intval($_POST['Fstatus']) : 1,
                    'FlimitBuy' => isset($_POST['FlimitBuy']) ? intval($_POST['FlimitBuy']) : 1,
                    'Fdetails' => isset($_POST['Fdetails']) ? trim($_POST['Fdetails']) : '',
                    'FaddTime' => time(),
                    'FaddPersonId' => $user_id,
                    'FaddpersonName' => $edit['Fname']
                );
//                判断上传的图片是否存在并且不能为空
                if (isset($_FILES['Fimg']['name']) && !empty($_FILES['Fimg']['name'])) {
//                基本使用方法:
                    $file = new ExtendsYspUploadFile();
                    $file->max_size = 2 * 1024 * 1024; //       //限制文件大小 字节
                    $file->allow_type = "gif/jpg/bmp/png"; //允许上传的文件类型
                    $file->input_name = "Fimg";           //表单中的文本域名称
                    $file->save_path = PATH_UPLOAD . 'proudct';      //保存路径
                    $file->rand_name = false;                   //随机文件名 (默认)
                    $file->reset_name = time() . '_' . BaseYspCookie::getCookie($_COOKIE['admin']['id']) . '_' . rand(0, 100);   //重命名
                    if ($file->save()) {
//                    echo "ok";               //保存文件，成功返回 true
                        $data['Fimg'] = str_replace(PATH_UPLOAD, '', $file->file_upload_path);
                    }
                }
                $rs = $this->M->Edit(self::$proudct_list, $data, 'Fid');
                if ($rs !== false) {
                    $href = str_replace('&way=E', '&way=S', URL);
                    parent::getMsg('right', '操作成功', $href);
                    exit;
                } else {
                    parent::getMsg('wrong', '对不起，操作失败', URL);
                    exit;
                }
            }
        }

        // delete
        if ($this->way == "D") {
            $rs = $this->M->Del(self::$proudct_list, 'Fid');
            if ($rs !== false) {
                $href = str_replace('&way=D', '&way=S', URL);
                parent::getMsg('right', '操作成功', $href);
                exit;
            } else {
                parent::getMsg('wrong', '对不起，操作失败', URL);
                exit;
            }
        }
    }

    /**
     * 商品添加多图上传处理
     */
    function proudctUploadImg() {
        $pid = isset($_GET['primarykey']) ? intval($_GET['primarykey']) : 0;
        $times = $this->M->getProductImgNum(self::$proudct_list, $pid);
        //                判断上传的图片是否存在并且不能为空
        if (isset($_FILES['Filedata']['name']) && !empty($_FILES['Filedata']['name'])) {
//                基本使用方法:
            $file = new ExtendsYspUploadFile();
            $file->max_size = 2 * 1024 * 1024; //       //限制文件大小 字节
            $file->allow_type = "gif/jpg/jpeg/bmp/png"; //允许上传的文件类型
            $file->input_name = "Filedata";           //表单中的文本域名称
            $file->save_path = PATH_UPLOAD . 'proudct';      //保存路径
            $file->rand_name = false;                   //随机文件名 (默认)
            $times++;
            $file->reset_name = time() . '_' . BaseYspCookie::getCookie($_COOKIE['admin']['id']) . '_' . $times;   //重命名
            if ($file->save()) {
//                    echo "ok";               //保存文件，成功返回 true
                $current_image_path = $data['Fimg'] = str_replace(PATH_UPLOAD, '', $file->file_upload_path);
                $this->M->updateMoreImage(self::$proudct_list, $pid, $current_image_path);
                echo 1;
                exit;
            } else {
                echo 0;
                exit;
            }
        }
    }

    // 商品菜单分类管理
    function productCate() {
        if ($this->way == "A") {
            if (!$_POST) {
                include PATH_VIEWS . 'web/product_category/add.php';
            } else {
                if (empty($_POST['Fname'])) {
                    parent::getMsg('wrong', '请填写分类名称', URL);
                }
                $data = array(
                    'Fname' => isset($_POST['Fname']) ? trim($_POST['Fname']) : ''
                );
                $rs = $this->M->addMenu(self::$product_categroy, $data);
                if ($rs > 0) {
                    parent::getMsg('right', '操作成功', URL, $time = 3);
                } else {
                    parent::getMsg('wrong', '操作失败', URL);
                }
            }
        }
        if ($this->way == "S") {
            //分页参数设置
            //当前页码
            $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            //每页条数
            $pagesize = 10;
            $page = ($page < 1) ? 1 : $page;
            //起始条数
            $start = ($page - 1) * $pagesize;
            //查询关键字
            $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
            $words_arr = BaseYsp::wordsFilter($keywords);
            $where = "WHERE Fid>=1";
            if (!empty($keywords)) {
                foreach ($words_arr as $wd) {
                    $where .= " AND (Fname LIKE '%$wd%')";
                }
            }
            $where = $keywords ? "WHERE Fname LIKE '%$keywords%'" : '';

            //取总记录数
            $total = $this->M->getTotal(self::$product_categroy, $where);
            $info_list = $this->M->getList(self::$product_categroy, '*', $where, 'ORDER BY Fid', "LIMIT $start,$pagesize");
            if ($total > 0) {
                $Pager = new ExtendsYspPager();
                $pagerlink = $Pager->getPager($total, $page, $pagesize);
            } else {
                $pagerlink = '对不起，没有相关信息';
            }
            include PATH_VIEWS . 'web/product_category/list.php';
        }
        if ($this->way == "E") {
            if (!$_POST) {
                $edit = $this->M->getView(self::$product_categroy, 'Fid');
                include PATH_VIEWS . 'web/product_category/edit.php';
            } else {
                $data = array(
                    'Fname' => isset($_POST['Fname']) ? trim($_POST['Fname']) : ''
                );
                $rs = $this->M->Edit(self::$product_categroy, $data, 'Fid');
                if ($rs !== false) {
                    $href = str_replace('&way=E', '&way=S', URL);
                    parent::getMsg('right', '操作成功', $href);
                    exit;
                } else {
                    parent::getMsg('wrong', '对不起，操作失败', URL);
                    exit;
                }
            }
        }
        if ($this->way == "D") {
            $rs = $this->M->Del(self::$product_categroy, 'Fid');
            if ($rs !== false) {
                $href = str_replace('&way=D', '&way=S', URL);
                parent::getMsg('right', '操作成功', $href);
                exit;
            } else {
                parent::getMsg('wrong', '对不起，操作失败', URL);
                exit;
            }
        }
    }

    /**
     * 商品信息分类
     */
    function productCategory() {
        if ($this->way == "A") {
            if (!$_POST) {
                $menu_list = $this->M->getList(self::$product_categroy);
                include PATH_VIEWS . 'web/product_class/add.php';
            } else {
                if ($_POST['FcateId'] == 0 || $_POST['FcateId'] == '') {
                    parent::getMsg('wrong', '请选择分类', URL);
                    exit;
                }
                $data = array(
                    'FcateId' => isset($_POST['FcateId']) ? trim($_POST['FcateId']) : '',
                    'Fname' => isset($_POST['Fname']) ? trim($_POST['Fname']) : ''
                );
                $rs = $this->M->addMenu(self::$product_categroy_list, $data);
                if ($rs > 0) {
                    parent::getMsg('right', '操作成功', URL);
                } else {
                    parent::getMsg('wrong', '操作失败', URL);
                }
            }
        }
        if ($this->way == "S") {
            //分页参数设置
            //当前页码
            $page = isset($_GET['page']) ? intval($_GET['page']) : 1;
            //每页条数
            $pagesize = 10;
            $page = ($page < 1) ? 1 : $page;
            //起始条数
            $start = ($page - 1) * $pagesize;
            //查询关键字
            $keywords = isset($_GET['keywords']) ? trim($_GET['keywords']) : '';
            $words_arr = BaseYsp::wordsFilter($keywords);
            $where = "WHERE Fid>=1";
            if (!empty($keywords)) {
                foreach ($words_arr as $wd) {
                    $where .= " AND (Fname LIKE '%$wd%')";
                }
            }
            $where = $keywords ? "WHERE Fname LIKE '%$keywords%'" : '';

            //取总记录数
            $total = $this->M->getTotal(self::$product_categroy_list, $where);
            $info_list = $this->M->getList(self::$product_categroy_list, '*', $where, 'ORDER BY Fid', "LIMIT $start,$pagesize");

            if ($total > 0) {
                $menu_list = $this->M->getList(self::$product_categroy);
                $menu_list_array = array();
                foreach ($menu_list as $ls) {
                    $menu_list_array[$ls['Fid']] = $ls['Fname'];
                }
                $Pager = new ExtendsYspPager();
                $pagerlink = $Pager->getPager($total, $page, $pagesize);
            } else {
                $pagerlink = '对不起，没有相关信息';
            }
            include PATH_VIEWS . 'web/product_class/list.php';
        }
        if ($this->way == "E") {
            if (!$_POST) {
                $menu_list = $this->M->getList(self::$product_categroy);
                $edit = $this->M->getView(self::$product_categroy_list, 'Fid');
                include PATH_VIEWS . 'web/product_class/edit.php';
            } else {
                if ($_POST['FcateId'] == 0 || $_POST['FcateId'] == '') {
                    parent::getMsg('wrong', '请选择分类', URL);
                    exit;
                }
                $data = array(
                    'FcateId' => isset($_POST['FcateId']) ? trim($_POST['FcateId']) : '',
                    'Fname' => isset($_POST['Fname']) ? trim($_POST['Fname']) : ''
                );
                $rs = $this->M->Edit(self::$product_categroy_list, $data, 'Fid');
                if ($rs !== false) {
                    $href = str_replace('&way=E', '&way=S', URL);
                    parent::getMsg('right', '操作成功', $href);
                    exit;
                } else {
                    parent::getMsg('wrong', '对不起，操作失败', URL);
                    exit;
                }
            }
        }
        if ($this->way == "D") {
            $rs = $this->M->Del(self::$product_categroy_list, 'Fid');
            if ($rs !== false) {
                $href = str_replace('&way=D', '&way=S', URL);
                parent::getMsg('right', '操作成功', $href);
                exit;
            } else {
                parent::getMsg('wrong', '对不起，操作失败', URL);
                exit;
            }
        }
    }

    function userInfo() {

        if ($this->way == 'A') {

//                array_unshift($cate_id_arr, '0');
//                $cate_id_arr = array_unique($cate_id_arr);
//                $cate_ids = implode(',', $cate_id_arr);
            $data = array(
                'Fname' => isset($_POST['Fway']) ? trim($_POST['Fway']) : '',
                'Faccount' => isset($_POST['Faccount']) ? trim($_POST['Faccount']) : '',
                'Fpassword' => isset($_POST['Fpassword']) ? md5(trim($_POST['Fpassword'])) : '',
                'FaddTime' => time()
            );
            $rs = $this->M->addMenu('tb_usre_copy', $data);
            if ($rs > 0) {
                echo "操作成功";
            } else {
                echo "操作失败";
            }
        }
        if ($this->way == "S") {
            $usre = isset($_POST['userName']) ? trim($_POST['userName']) : '';
            $password = isset($_POST['passWord']) ? md5(trim($_POST['passWord'])) : '';
            $info = $this->M->getOneRow('tb_usre_copy', 'Fid,Fname,Faccount', "WHERE (Faccount='{$usre}' AND Fpassword='$password')");
            // print_r($info);exit;
            if (!isset($info['Fid'])) {
                echo '对不起，您输入的登录信息有误，请重新输入。';
                return FALSE;
            } else {
                echo "登录成功";
            }
        }
    }

}
